﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Drawing;

namespace ADNLib
{
    public enum ADNDocumentType
    {
        Animation,
        Character,
        SwapGroup,
        Document,
        Unknown
    }

	[XmlRoot("ANIMATION")]
	public class Animation
	{
		private List<Layer> layers = new List<Layer>();
        private Size resolution = new Size();
        private int fps = 25;
        private ADNDocumentType docType = ADNDocumentType.Unknown;

		[XmlElement("LAYER")]
		public List<Layer> Layers
		{
			get { return layers; }
			set { layers = value; }
		}

		[XmlElement]
		public Size Resolution
		{
			get { return resolution; }
			set { resolution = value; }
		}

        [XmlElement]
        public int FPS
        {
            get { return fps; }
            set { fps = value; }
        }

        [XmlElement]
        public ADNDocumentType DocumentType
        {
            get { return docType; }
            set { docType = value; }
        }

		public int GetTotalFrames()
		{
			//loop through each layer
			//goto last frame & get frame.start + frame.span -1
			//return longest of all layers
			int maxFrame = 0;

			for (int i = 0; i < layers.Count; i++)
			{
				int lastFrame = layers[i].Frames[layers[i].Frames.Count -1].StartFrame + 
					layers[i].Frames[layers[i].Frames.Count -1].Span;
				
				if(lastFrame > maxFrame) { maxFrame = lastFrame; }
			}

			return maxFrame;
		}
	}
}
